﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Practices.Unity;
using Windows.UI.Xaml;
using System.Reflection;

namespace UWP.Douban.Mvvm
{
    public class Locator
    {
        private  IUnityContainer _unityContainer;
        public Locator()
        {
            _unityContainer = new UnityContainer();
            
            var properties = this.GetType().GetRuntimeProperties()
                .Where(o => o.Name.Contains("Vm"));

            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                properties = properties.Where(o => o.Name.Contains("Sample"));
            }
            else
            {
                properties = properties.Where(o => !o.Name.Contains("Sample"));
            }

            foreach (var property in properties)
            {
                var propertyType = property.PropertyType;
                var instance = _unityContainer.Resolve(propertyType);
                property.SetValue(this, instance);
            }
        }

        public static Locator Instance
        {
            get
            {
                var m = Application.Current.Resources["Locator"] as Locator;
                return m;
            }
        }

        public MainVm MainVm { get; private set; } 
        public MainVmSample MainVmSample { get; private set; }

        public LoginVm LoginVm { get; private set; }
        public LoginVmSample LoginVmSample { get; private set; }


        public AnonymousTopicVm AnonymousTopicVm { get; private set; }
        public AnonymousTopicVmSample AnonymousTopicVmSample { get; private set; }

        public DouImVm DouImVm { get; private set; }
        public DouImVmSample DouImVmSample { get; private set; }

        public GroupDetailVm GroupDetailVm { get; private set; }
        public GroupDetailVmSample GroupDetailVmSample { get; private set; }

        public GroupTopicVm GroupTopicVm { get; private set; }
        public GroupTopicVmSample GroupTopicVmSample { get; private set; }

        public MeVm MeVm { get; private set; }
        public MeVmSample MeVmSample { get; private set; }

        public MyReminderVm MyReminderVm { get; private set; }
        public MyReminderVmSample MyReminderVmSample { get; private set; }

        public MyTopicVm MyTopicVm { get; private set; }
      
        public MyTopicVmSample MyTopicVmSample { get; private set; }

        public MyGroupVm MyGroupVm { get; private set; }
        public MyGroupVmSample MyGroupVmSample { get; private set; }

        public ReminderDetailVm ReminderDetailVm { get; private set; }
        public ReminderDetailVmSample ReminderDetailVmSample { get; private set; }

        public ReplyCommentVm ReplyCommentVm { get; private set; }
        public ReplyCommentVmSample ReplyCommentVmSample { get; private set; }

        public DouImDetailVm DouImDetailVm { get; private set; }
        public DouImDetailVmSample DouImDetailVmSample { get; private set; }

        public TopicCommentVm TopicCommentVm { get; private set; }
        public TopicCommentVmSample TopicCommentVmSample { get; private set; }

        public TopicDetailVm TopicDetailVm { get; private set; }
        public TopicDetailVmSample TopicDetailVmSample { get; private set; }
    }
}
